package com.feature.shop.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.feature.core.domain.PageVo;
import com.feature.core.domain.Response;
import com.feature.shop.auth.api.vo.LoginUserVo;
import com.feature.shop.core.util.ShopApplictionContext;
import com.feature.shop.user.api.ShopRoleApi;
import com.feature.shop.user.api.request.ShopRoleAddRequest;
import com.feature.shop.user.api.request.ShopRoleDelRequest;
import com.feature.shop.user.api.request.ShopRolePageRequest;
import com.feature.shop.user.api.request.ShopRoleUpdateRequest;
import com.feature.shop.user.api.vo.ShopRoleVo;
import com.feature.shop.user.service.ShopRoleService;

import jakarta.validation.Valid;

/***
 * 菜单表Controller
 */
@RestController
public class ShopRoleController implements ShopRoleApi {

    @Autowired
    private ShopRoleService shopRoleService;

    @Override
    public Response<PageVo<ShopRoleVo>> queryRolePage(ShopRolePageRequest req) {
        PageVo<ShopRoleVo> result = shopRoleService.findPageList(req);
        return Response.ok(result);
    }

    @Override
    public Response<?> addRole(@Valid ShopRoleAddRequest req) {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        shopRoleService.addRole(req, loginUser);
        return Response.ok();
    }

    @Override
    public Response<?> updateRole(@Valid ShopRoleUpdateRequest req) {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        shopRoleService.updateRole(req, loginUser);
        return Response.ok();
    }

    @Override
    public Response<?> delRole(@Valid ShopRoleDelRequest req) {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        shopRoleService.delRole(req, loginUser);
        return Response.ok();
    }

}
